package Reseau;

import java.awt.Point;
import java.awt.geom.Line2D;

public class Segment {
	private Noeud noeudA;
	private Noeud noeudB;
	
	public Segment(Noeud noeudA, Noeud noeudB){
		this.noeudA = noeudA;
		this.noeudB = noeudB;
	}
	
	public Noeud getNoeudA(){
		return noeudA;
	}
	
	public Noeud getNoeudB(){
		return noeudB;
	}
	
	public Point getDistance(){
		return new Point(Math.abs(noeudB.getX() - noeudA.getX()), Math.abs(noeudB.getY() - noeudA.getY()));
	}
	
	public double getLongueur(){
		Point dist = getDistance();
		return Math.sqrt(Math.pow(dist.x, 2) + Math.pow(dist.y, 2));
	}
	
	public String toString(){
		return "1 (" + noeudA.toString() + ") 2 (" + noeudB.toString() + ") - Dist: " + getDistance() + " Long: " + getLongueur();
	}
	
	public boolean isClicked(int x, int y){
		return Line2D.ptSegDist(noeudA.getXMid(), noeudA.getYMid(), noeudB.getXMid(), noeudB.getYMid(), x, y) < 5;
	}
}
